package myjava.SocketProgramming;

import java.io.*;
import java.net.Socket;

public class JavaSocket {

	   public static final String IP_ADDR = "10.1.1.55";
	    public static final int PORT = 9000;   
	    public static final String str = "<xa 0 32>\r\n";
	      
	    public static void main(String[] args) {    
	        System.out.println("Client Start....");    
	        int counter = 0;
	        //while (true) {    
	            Socket socket = null;  
	            try {  
	                
	                socket = new Socket(IP_ADDR, PORT);  
	                socket.setKeepAlive(true);
	                       
	                  
	                    
	                DataOutputStream out = new DataOutputStream(socket.getOutputStream());
	                InputStream input = socket.getInputStream();
	                BufferedReader in = new BufferedReader(new InputStreamReader(input));
	                char[] sn = new char[1000];
                
	                while(counter<100)
	                {
		                out.writeUTF(str);   

		                in.read(sn);
		                String sc = new String(sn);    
		                System.out.println(sc);

		                Thread.sleep(100);
		                counter++;
	                }
	                  
	                out.close();  
	                input.close();
	            } catch (Exception e) {  
	                System.out.println("Client Exception:" + e.getMessage());   
	            } finally {  
	                if (socket != null) {  
	                    try {  
	                        socket.close();  
	                    } catch (IOException e) {  
	                        socket = null;   
	                        System.out.println("Client finally Exception:" + e.getMessage());   
	                    }  
	                }  
	            }  
	    }    
}
